package com.gilight.base.controller;

import com.gilight.base.admin.config.AdminSysConfigService;
import com.gilight.base.base.ResultEntity;
import com.gilight.base.base.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/web/codeGenerator")
public class SysConfigController {
    @Autowired
    private AdminSysConfigService adminSysConfigService;

    /**
     *
     *
     * @param configs [{"key":"accessKeyId","value":"1"},{"key":"accessKeySecret","value":"1"},
     *                {"key":"endpoint","value":"1"},
     *                {"key":"bucket","value":"2"},{"key":"dir","value":"3"},{"key":"baseUrl","value":"4"}]
     * @param prefix  OSS_CONFIG
     *                prefix 枚举     public static final String WX_APP_CONFIG_PREFIX = "WX_APP_CONFIG:";
     *
     *     WX_PAY_CONFIG  微信支付配置
     *     SMS_CONFIG     短信配置
     *     OSS_CONFIG     阿里云对象存储配置
     *     OPEN_SEARCH_CONFIG  阿里云开放搜索配置
     *     ORDER_CONFIG        订单配置
     *     ADVERT_CONFIG:
     *     SYSTEM_CONFIG:       系统配置
     *     ADMIN_NOTIFY_CONFIG   通知配置
     *     MAP_KEY                QQ地图配置
     * @return
     */
    @RequestMapping(value = "/save")
    public ResultEntity saveConfig(String configs, String prefix) {
        try {
            adminSysConfigService.save(configs,prefix,1l);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return ResultEntity.success();
    }
    @RequestMapping(value = "/get-data", method = {RequestMethod.GET})
    public ResultEntity getData(Long adminId) {
        ResultEntity resultEntity = ResultEntity.success();
        try {
            resultEntity.setData(adminSysConfigService.getData(adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }
}
